package com.jlastu.znb.view;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.jlastu.znb.R;
import com.jlastu.znb.adapter.FootprintListAdapter;
import com.jlastu.znb.contract.FootprintContract;
import com.jlastu.znb.entity.Goods;
import com.jlastu.znb.presenter.FootprintPresenter;

import java.util.ArrayList;
import java.util.List;

public class FootprintActivity extends AppCompatActivity implements FootprintContract.IFootprintView{
    private ImageView mBack;
    private FootprintListAdapter mFootprintListAdapter;
    private FootprintContract.IFootprintPresenter mFootprintPresenter;
    private RecyclerView mGoodsRecyclerView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_footprint);

        mFootprintPresenter = new FootprintPresenter(this, this);

        // 使用成员变量mGoodsRecyclerView而不是局部变量recyclerView
        mGoodsRecyclerView = findViewById(R.id.footprint_listView);
        StaggeredGridLayoutManager staggeredGridLayoutManager =
                new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL); // 假设您想要2列
        mGoodsRecyclerView.setLayoutManager(staggeredGridLayoutManager); // 使用成员变量
        mFootprintListAdapter = new FootprintListAdapter(new ArrayList<>());
        mGoodsRecyclerView.setAdapter(mFootprintListAdapter);

        mBack = findViewById(R.id.back);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mFootprintPresenter.getGoodsList(); // 获取已收藏商品列表
    }

    @Override
    public void showGoodsList(List<Goods> goodsList) {
        // 更新适配器中的数据
        mFootprintListAdapter.updateData(goodsList);
        // 通知RecyclerView数据已更新
        mFootprintListAdapter.notifyDataSetChanged();
    }
}
